//
//  main.cpp
//  特殊函数和成员
//
//  Created by Robin Guo on 2017/9/23.
//  Copyright © 2017年 Robin Guo. All rights reserved.
//

#include <iostream>
#include "FindRoot.hpp"

using namespace std;

typedef int(typeFunc) (int);

class Teacher;
class Student;

class Teacher {
private:
    void test();
    int num;
    
public:
    void input(int c);
    friend void show(Teacher &);
    int getscore(Student &);
};

class Student {
private:
    int score;
    
public:
    Student();
    typeFunc s;
    
    static const int total = 150;
    void input(int c);
    friend void show (Student &);
    friend int Teacher::getscore(Student &m);
    friend Teacher;
    
    void myConstFunc() const;
};

// 老师的函数实现
void Teacher::input(int c){
    num=c;
}

// 教师现在能无限制的访问stuent类的对象成员了
int Teacher::getscore(Student &m) {
    return m.score;
}

void show(Teacher &t) {
    cout << t.num << endl;
    t.test();
    t.input(10);
}

void Teacher::test(){
    cout << "测试学生" << endl;
}

// 学生的函数实现
Student::Student() {
    score = 0;
}

void Student::input(int c) {
    score = c;
}

void show(Student &s) {
    cout << s.score << endl;
}

int Student::s(int a) {
    cout << "type def a func " << a << endl;
    return a + 1;
}

//int Student::*s(int i) {
//    cout << "指向函数的指针实现了函数" << endl;
////    int b = ew;
//    return 2;
//}


void Student::myConstFunc() const {
    cout << "only const obj can excute const func" << endl;
}

//int Student::total = 100;
//int Student::score = 20;
void Read (float &,float &,float &);

int main(int argc, const char * argv[]) {
    /*
     静态成员
     友元函数和成员
     */
    // 友元函数解决的问题：两个概念上相近的类要求其中一个类无限制的存取另一个类的成员；
    Student s;
    s.input(100);
    
    Teacher t;
    t.input(10);
    
    show(t);
    show(s);
    
    const Student s1;
    s1.myConstFunc();
    int rs = s.s(20);
    
    int (Student:: *ps)(int) = &Student::s;
    
    int rs0 = (s.*ps)(200);
    
    
//    s.total = 101;
    cout << s.total << " \n " << rs << " \n " << rs0 << endl;
    
    cout << t.getscore(s) << endl;
    
//    int r = s.s(20);
//    cout << r << endl;
    
//    float a,b,c;
    
    
//    for (; ; ) {
//        Read(a, b, c);
//        FindRoot fr(a,b,c);
//        fr.Find();
//        fr.Display();
//    }
    
//    test obj(1,3.2,'w');
    
    
    
    
    return 0;
}

void Read (float &a,float &b,float &c) {
    cout << "请输入方程式系数a：" << endl;
    cin >> a;
    if (a == 0) {
        getchar();
        return;
    }
    
    cout << "请输入方程式系数b：" << endl;
    cin >> b;
    
    cout << "请输入方程式系数c：" << endl;
    cin >> c;
    
}
